package com.isatechindonesia.pilihsaya;

import com.markupartist.android.widget.ActionBar;
import com.markupartist.android.widget.ActionBar.IntentAction;
import com.mobile.pilihsaya.ServiceHelper;


import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class DaftarActivity extends Activity {
	
//	public String nama = "Hinova Rezha Ulinuha";
//	public String email = "rezhahinova@gmail.com";
//	public String alamat = "pokoh umbulmartani ngemplak sleman";
	
	
	public String nama,email,alamat;
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_daftar);
		ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar_post);
		actionBar.setTitle("Daftar");
		

		actionBar.setHomeAction(new IntentAction(this, LoginActivity
				.createIntent(this), R.drawable.ic_action_back));
		
		final TextView txtNama = (TextView) findViewById(R.id.inputNama);
		final TextView txtEmail = (TextView) findViewById(R.id.inputEmail);
		final TextView txtAlamat = (TextView) findViewById(R.id.inputAlamat);
		
		Button btnDaftar = (Button) findViewById(R.id.btnDaftar);
		btnDaftar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				nama = txtNama.getText().toString();
				email = txtEmail.getText().toString();
				alamat = txtAlamat.getText().toString();
				new DaftarTask().execute();
				
			}
		});
	}
		public class DaftarTask extends AsyncTask<String, Void, Boolean> {

			
			ProgressDialog dialog = new ProgressDialog(DaftarActivity.this);

			
			protected void onPreExecute() {
				dialog.setMessage(" terimakasih ");
				dialog.show();
			}

			protected void onPostExecute(Boolean result) {
				dialog.dismiss();
				if (result == true) {
					Toast.makeText(DaftarActivity.this, "Registration Success",
							Toast.LENGTH_LONG).show();
					finish();

				} else {
					Toast.makeText(DaftarActivity.this, "Registration Failed",
							Toast.LENGTH_LONG).show();
				}

			}

			@Override
			protected Boolean doInBackground(String... params) {
				// TODO Auto-generated method stub
				ServiceHelper srv = new ServiceHelper();

				if (srv.daftar(DaftarActivity.this, nama, email, alamat)) {
					return true;
				} else {
					return false;
				}
			}

		}

	}
